/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ryopei.hatena;

import java.util.regex.Pattern;
import javax.swing.RowFilter;
import javax.swing.RowFilter.Entry;

/**
 *
 * @author ryohei
 */
public class SimpleEntryModelRowFilter extends RowFilter <SimpleEntryModel,Integer> {

    //フィルタ条件
    private int condType;
    private String condText;
    
    public SimpleEntryModelRowFilter(int condType, String condText) {
        this.condType = condType;
        this.condText = condText;
    }

    @Override
    public boolean include(Entry<? extends SimpleEntryModel, ? extends Integer> entry) {

        SimpleEntryModel simpleEntryModel = entry.getModel();
        SimpleEntry simpleEntry = simpleEntryModel.getEntry(entry.getIdentifier());

        Pattern p;
        switch (condType) {
            case 0:
                p = Pattern.compile(".*" + condText + ".*");
                break;
            case 1:
                p = Pattern.compile(condText + ".*");
                break;
            case 2:
                p = Pattern.compile(condText + ".*");
                break;
            default:
                return true;
        }
        return p.matcher(simpleEntry.getTitle()).matches();


    }

}
